<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="UTF-8" />
		<meta name="author" content="wangbo" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<script>
			// 0-1的随机数			 
      let fn6 = () => {
				// Math.random() 产生0-1的随机小数
				// 随机数产生一次,
				let num = Math.ceil(Math.random()*100)
				console.log(num)
				let title = "请输入你猜的数";
				// 是猜对了,还是没猜对
				let istrue = false;
				for (let i = 3; i >= 1; i--) {
					// 接收输入的数据					
					let input = Number.parseInt(prompt(title));
					if (input>num) {
						title="您猜大了,还有"+(i-1)+"次机会"
					}else if (input<num) {
						title="您猜小了,还有"+(i-1)+"次机会"
					}else if(input==num){
						istrue = true;
						alert("猜对了恭喜")
						// 猜对了,没必要继续终止循环
						break;
					}
				}
				// 取反
				if(!istrue){
					alert("3次机会用完了,下次再来吧")
				}
			}
			let num ;
			// NaN not a number
			// console.log(num+1)
			fn6()
		</script>
	</body>
</html>
